package com.jxc.servlet.Charset;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/Charset/CharsetServlet")
public class CharsetServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*
        * req.setCharacterEncoding("utf-8")用于将请求体中的字符集转换成utf-8，但是只能对post生效，因为get没有请求体,
        * 一定要写在第一行才能生效。
        * */
        req.setCharacterEncoding("utf-8");
        // 获取请求中的信息
        String name = req.getParameter("name");
        String address = req.getParameter("address");
        System.out.println(name+":"+address);
    }
}
